package pl.szpadel.android.gadu.packets;

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;

import pl.szpadel.android.gadu.CommunicationService;
import android.util.Log;

public class UserlistReply80 extends ReceivedPacket {
	
	// fields
	public boolean last;
	public ByteBuffer data;
	
	// gg values
	@SuppressWarnings("unused")
	static private final int GG_USERLIST_PUT_REPLY = 0x00;
	@SuppressWarnings("unused")
	static private final int GG_USERLIST_PUT_MORE_REPLY = 0x02;
	@SuppressWarnings("unused")
	static private final int GG_USERLIST_GET_MORE_REPLY = 0x04;
	static private final int GG_USERLIST_GET_REPLY = 0x06;

	public UserlistReply80(Header hdr, InputStream stream) throws IOException {
		super(hdr, stream);
	}

	public UserlistReply80(Header hdr, ReadableByteChannel channel)
			throws IOException {
		super(hdr, channel);
	}

	@Override
	protected void readFromBuffer(ByteBuffer buffer) {
		byte type = buffer.get();
		
		Log.i(CommunicationService.TAG, "UserlistReply80 decoding, type: 0x" + Integer.toHexString(type));
		last = (type == GG_USERLIST_GET_REPLY);
		data = ByteBuffer.allocate(buffer.remaining());
		data.put(buffer);
	}
	
	public String toString() {
		return "UserlistReply80 [ last=" + last + ", data len=" + ((data!=null)?data.capacity():0) + " ]";
	}

}
